﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using FastReflectionLib;
using CDCW.API;
using Newtonsoft.Json;
using CDCW.Data;
using System.Data;
using Newtonsoft.Json.Linq;
using System.Net;
using System.Configuration;
using System.IO;
using System.Xml;
using Newtonsoft.Json.Converters;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading.Tasks;

namespace CDCW.API
{
    public class Commanage : IWsService
    {
        public void ProcessRequest(HttpContext context, ref Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            MethodInfo methodInfo = typeof(Commanage).GetMethod(msg.Action.ToUpper());
            Commanage model = new Commanage();
            methodInfo.FastInvoke(model, new object[] { context, msg, P1, P2, UserInfo });
        }


        #region 登录注册
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1">用户名</param>
        /// <param name="P2">密码（未解码的）</param>
        /// <param name="UserInfo"></param>
        public void LOGIN(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string password = context.Request["password"];
            string username = context.Request["UserName"];
            password = CommonHelp.GetMD5(password);

            JH_Auth_User userInfo = new JH_Auth_User();

            List<JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => (d.UserName == username || d.mobphone == username) && d.UserPass == password).ToList();

            if (userList.Count() == 0)
            {
                msg.ErrorMsg = "用户名或密码不正确";
                return;
            }
            else
                userInfo = userList[0];

            if (userInfo == null)
            {
                msg.ErrorMsg = "用户名或密码不正确";
            }
            else
            {
                //if (string.IsNullOrEmpty(userInfo.p))
                //{
                //    userInfo.pccode = System.Guid.NewGuid().ToString();
                //}
                //new QJY_UserB().Update(userInfo);
                msg.Result = userInfo.UserName;
                msg.Result1 = userInfo.ID;
                //LOG异步
                try
                {
                    Task.Factory.StartNew<string>(() =>
                    {
                        new JH_Auth_LogB().Insert(new JH_Auth_Log()
                        {
                            LogType = "PCLOGIN",
                            LogContent = "用户" + userInfo.UserName + "登录，登录时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 登录地点:" + CommonHelp.getIpAddr(),
                            CRUser = userInfo.ID.ToString(),
                            CRDate = DateTime.Now
                        });
                        return "";
                    });


                }
                catch { }
            }
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void REGISTER(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            //JObject tt = (JObject)JsonConvert.DeserializeObject(P1);
            //string username = tt["UserRealName"].ToString();
            //if (username == "")
            //{
            //    msg.ErrorMsg = "姓名不能为空!";
            //}
            //string mobile = tt["Phone"].ToString();
            //if (string.IsNullOrEmpty(mobile))
            //{
            //    msg.ErrorMsg = "手机号不能为空!";
            //}
            //if (string.IsNullOrEmpty(tt["Pasword"].ToString()))
            //{
            //    msg.ErrorMsg = "密码不能为空!";
            //}
            //var userlist = new QJY_UserB().GetEntities(p => p.Phone == mobile);
            //if (userlist.Count() > 0)
            //{
            //    msg.ErrorMsg = "此手机已注册用户";
            //}
            //if (msg.ErrorMsg == "")
            //{
            //    QJY_User user = tt.ToObject<QJY_User>();
            //    user.CRDate = DateTime.Now;
            //    user.CRUser = "";
            //    user.UserName = user.Phone;
            //    string password = user.Pasword;
            //    user.Pasword = CommonHelp.GetMD5(password);
            //    new QJY_UserB().Insert(user);
            //    msg.Result = user;
            //    string content = "您的课程管理系统账号已注册成功，信息如下：\r\n登录账号：" + user.UserName + "\r\n密码：" + password + "\r\n,如非本人操作，请忽略本短信";
            //    msg.Result1 = content;
            //}
        }

        /// <summary>
        /// 校友注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void ZC(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strYHM = P1;//用户名
            string strRealname = P2;//真实姓名
            string psd = context.Request.QueryString["PSD"] ?? "";
            string mobile = context.Request.QueryString["MOBILE"] ?? "";
            JH_Auth_User USERMODEL = new JH_Auth_UserB().GetEntity(d => d.UserName == strYHM);
            //msg.ErrorMsg = "用户名已注册";
            if (USERMODEL != null)
            {
                msg.ErrorMsg = "用户名已注册";
               
                // alert("122");
            }
            else
            {
                JH_Auth_User MODEL = new JH_Auth_User();

                JH_Auth_UserRole MODELROLE = new JH_Auth_UserRole();

                MODELROLE.UserName = strYHM;
                MODELROLE.RoleCode = 3;

                MODEL.UserName = strYHM;
                MODEL.UserRealName = strRealname;
                MODEL.UserPass = psd;
                MODEL.mobphone = mobile;
                MODEL.IsUse = "Y";
                MODEL.STATUS = "Y";
                MODEL.BranchCode = 2;
                MODEL.CRDate = DateTime.Now;
                new JH_Auth_UserB().Insert(MODEL);

                new JH_Auth_UserRoleB().Insert(MODELROLE);
                msg.Result = MODEL;


            }


        }
        /// <summary>
        /// 检查手机号是否注册
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void CHECKREGISTERPHONE(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var userList = new JH_Auth_UserB().GetEntities(p => p.telphone == P1.Trim());
            if (userList.Count() > 0)
            {
                msg.ErrorMsg = "此手机已注册用户，请更换手机号继续注册";
            }
        }
        /// <summary>
        /// 发送手机验证码
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void SENDCHKMSG(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            if (!string.IsNullOrEmpty(P1))
            {
                string code = CommonHelp.numcode(4);
                try
                {
                    string type = context.Request["type"] ?? "";
                    string content = "";
                    switch (type)
                    {
                        default:
                            content = "教师助手注册验证码为：" + code + "，如非本人操作，请忽略本短信";
                            break;
                    }
                    CommonHelp.SendDX(P1, content, "");
                    msg.Result = CommonHelp.GetMD5(code);
                }
                catch
                {
                    msg.ErrorMsg = "发送验证码失败";
                }
            }
        }
        #endregion

        #region 门户网站

        #region 首页列表
        /// <summary>
        /// 首页列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETINDEXLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            //DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LMGL where TopID=0 and IsDel=0  order by number ");

            //dt.Columns.Add("Item", Type.GetType("System.Object"));
            //foreach (DataRow dr in dt.Rows)
            //{
            //    DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by number ");
            //    dtItem.Columns.Add("List", Type.GetType("System.Object"));
            //    foreach (DataRow drItem in dtItem.Rows)
            //    {
            //        DataTable dtItemList = new JH_MH_XWGLB().GetDTByCommand("select top 6 * from JH_MH_XWGL where  Type=" + drItem["ID"].ToString() + " order by CRDate desc ");
            //        drItem["List"] = dtItemList;
            //    }

            //    dr["Item"] = dtItem;
            //}
            //msg.Result = dt;

            msg.Result = new JH_MH_LMGLB().GetDTByCommand(" select top 4 * from JH_MH_XWGL where isnull(Files,'')!='' and Type=5 order by CRDate desc ");//图片新闻
            msg.Result1 = new JH_MH_LMGLB().GetDTByCommand(" select top 7 * from JH_MH_XWGL order by CRDate desc ");//最新新闻
            msg.Result2 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_TZGG order by CRDate desc ");//通知公告
            msg.Result3 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_CG_CGGL where Status='1' order by CRDate desc ");//成果展示
            msg.Result4 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_CG_FMZL order by CRDate desc ");//专利展示
            msg.Result5 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LJGL order by CRDate desc ");//链接
        }

        #endregion

        #region 专利新闻1
        /// <summary>
        /// 首页列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETINDEXLISTXW(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            //DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LMGL where TopID=0 and IsDel=0  order by number ");

            //dt.Columns.Add("Item", Type.GetType("System.Object"));
            //foreach (DataRow dr in dt.Rows)
            //{
            //    DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by number ");
            //    dtItem.Columns.Add("List", Type.GetType("System.Object"));
            //    foreach (DataRow drItem in dtItem.Rows)
            //    {
            //        DataTable dtItemList = new JH_MH_XWGLB().GetDTByCommand("select top 6 * from JH_MH_XWGL where  Type=" + drItem["ID"].ToString() + " order by CRDate desc ");
            //        drItem["List"] = dtItemList;
            //    }

            //    dr["Item"] = dtItem;
            //}
            //msg.Result = dt;

            msg.Result = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=5  order by CRDate desc ");//最新新闻
            msg.Result1 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=3  order by CRDate desc ");//双创信息
            msg.Result2 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=34  order by CRDate desc ");//政策法规
            msg.Result3 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=35  order by CRDate desc ");//办事指南
            msg.Result4 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=36  order by CRDate desc ");//双创先锋
            msg.Result5 = new JH_MH_LMGLB().GetDTByCommand(" select top 6 * from JH_MH_XWGL where Type=37  order by CRDate desc ");//创业活动
        }

        #endregion
        #region 专利新闻12
        /// <summary>
        /// 首页列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETINDEXLISTXW2(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            //DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LMGL where TopID=0 and IsDel=0  order by number ");

            //dt.Columns.Add("Item", Type.GetType("System.Object"));
            //foreach (DataRow dr in dt.Rows)
            //{
            //    DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by number ");
            //    dtItem.Columns.Add("List", Type.GetType("System.Object"));
            //    foreach (DataRow drItem in dtItem.Rows)
            //    {
            //        DataTable dtItemList = new JH_MH_XWGLB().GetDTByCommand("select top 6 * from JH_MH_XWGL where  Type=" + drItem["ID"].ToString() + " order by CRDate desc ");
            //        drItem["List"] = dtItemList;
            //    }

            //    dr["Item"] = dtItem;
            //}
            //msg.Result = dt;

            msg.Result = new JH_MH_LMGLB().GetDTByCommand(" select top 1 * from JH_MH_XWGL where Type=37 and isnull(Files,'')!='' order by CRDate desc ");//创业活动
            msg.Result1 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_XWGL where Type=38  order by CRDate desc ");//专家团队
            msg.Result2 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_XWGL where Type=39  order by CRDate desc ");//企业展示
            msg.Result3 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_TZGG order by CRDate desc ");//通知公告
            msg.Result4 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_XWGL where Type=40  order by CRDate desc ");//合作机构
            msg.Result5 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LJLX order by Type ");//连接类型
            //msg.Result3 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=35  order by CRDate desc ");//办事指南
            //msg.Result4 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=36  order by CRDate desc ");//双创先锋
            //msg.Result5 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=37  order by CRDate desc ");//创业活动
        }

        public void GETINDEXLISTXW3(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            //DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LMGL where TopID=0 and IsDel=0  order by number ");

            //dt.Columns.Add("Item", Type.GetType("System.Object"));
            //foreach (DataRow dr in dt.Rows)
            //{
            //    DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by number ");
            //    dtItem.Columns.Add("List", Type.GetType("System.Object"));
            //    foreach (DataRow drItem in dtItem.Rows)
            //    {
            //        DataTable dtItemList = new JH_MH_XWGLB().GetDTByCommand("select top 6 * from JH_MH_XWGL where  Type=" + drItem["ID"].ToString() + " order by CRDate desc ");
            //        drItem["List"] = dtItemList;
            //    }

            //    dr["Item"] = dtItem;
            //}
            //msg.Result = dt;
            msg.Result = new JH_MH_LMGLB().GetDTByCommand(" select top 6 * from JH_MH_XWGL where Type=45  order by CRDate desc ");//推荐成果前8条
           // msg.Result = new JH_MH_LMGLB().GetDTByCommand(" select top 1 * from JH_MH_XWGL where Type=37 and isnull(Files,'')!='' order by CRDate desc ");//创业活动
            msg.Result1 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_XWGL where Type=45  order by CRDate desc ");//推荐成果
            //msg.Result2 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_XWGL where Type=39  order by CRDate desc ");//企业展示
            //msg.Result3 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_TZGG order by CRDate desc ");//通知公告
            //msg.Result4 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_XWGL where Type=40  order by CRDate desc ");//合作机构
            //msg.Result5 = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LJLX order by Type ");//连接类型
            //msg.Result3 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=35  order by CRDate desc ");//办事指南
            //msg.Result4 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=36  order by CRDate desc ");//双创先锋
            //msg.Result5 = new JH_MH_LMGLB().GetDTByCommand(" select top 8 * from JH_MH_XWGL where Type=37  order by CRDate desc ");//创业活动
        }

        #endregion

        #region 栏目列表
        /// <summary>
        /// 栏目列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETLMLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_MH_LMGL where TopID=0 and IsDel=0  order by number ");

            dt.Columns.Add("Item", Type.GetType("System.Object"));
            foreach (DataRow dr in dt.Rows)
            {
                DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by number ");
                dr["Item"] = dtItem;
            }
            msg.Result = dt;
        }

        #endregion

        #region 栏目默认列表
        /// <summary>
        /// 栏目默认列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETLMMRLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            DataTable dtIndex = new JH_MH_LMGLB().GetDTByCommand("select * from JH_MH_LMGL where  TopID=" + P1 + " and IsDel=0  order by number ");
            dtIndex.Columns.Add("List", Type.GetType("System.Object"));
            foreach (DataRow drIndex in dtIndex.Rows)
            {
                DataTable dtIndexList = new JH_MH_XWGLB().GetDTByCommand("select top 5 * from JH_MH_XWGL where  Type=" + drIndex["ID"].ToString() + " order by CRDate desc ");
                drIndex["List"] = dtIndexList;
            }
            msg.Result = dtIndex;
        }

        #endregion

        #region 栏目内容列表
        /// <summary>
        /// 栏目内容列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETNRLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWhere = " Type=" + P1;
            if (P2 != "")
            {
                strWhere += " and Title like '%" + P2 + "%'";
            }
            int page = 0;
            int pagecount = 8;
            int.TryParse(context.Request.QueryString["p"] ?? "1", out page);
            int.TryParse(context.Request.QueryString["pagecount"] ?? "8", out pagecount);//页数
            page = page == 0 ? 1 : page;
            int total = 0;
            DataTable dt = new DataTable();
            dt = new JH_MH_XWGLB().GetDataPager("JH_MH_XWGL ", "*", pagecount, page, " CRDate desc", strWhere, ref total);

            msg.Result = dt;
            msg.Result1 = total;
        }

        #endregion

        #region 通知公告列表
        /// <summary>
        /// 栏目内容列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETTZGGNRLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWhere = " Type=" + P1;
            if (P2 != "")
            {
                strWhere += " and Title like '%" + P2 + "%'";
            }
            int page = 0;
            int pagecount = 8;
            int.TryParse(context.Request.QueryString["p"] ?? "1", out page);
            int.TryParse(context.Request.QueryString["pagecount"] ?? "8", out pagecount);//页数
            page = page == 0 ? 1 : page;
            int total = 0;
            DataTable dt = new DataTable();
            dt = new JH_MH_XWGLB().GetDataPager("JH_MH_TZGG ", "*", pagecount, page, " CRDate desc", strWhere, ref total);

            msg.Result = dt;
            msg.Result1 = total;
        }

        #endregion

        #region 栏目内容
        /// <summary>
        /// 栏目内容
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETNR(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var nr = new JH_MH_XWGLB().GetEntities(" ID='" + P1 + "' ").FirstOrDefault();
            msg.Result = nr;
        }

        #endregion

        #region 公告内容
        /// <summary>
        /// 公告内容
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETGG(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var nr = new JH_MH_TZGGB().GetEntities(" ID='" + P1 + "' ").FirstOrDefault();
            msg.Result = nr;
        }

        #endregion

        #endregion

        #region 成果展示

        #region 类型列表
        /// <summary>
        /// 类型列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETFLLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_CG_LXGL where TopID=0 and IsDel=0  order by CRDate desc ");

            dt.Columns.Add("Item", Type.GetType("System.Object"));
            foreach (DataRow dr in dt.Rows)
            {
                DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_CG_LXGL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by CRDate desc ");
                dr["Item"] = dtItem;
            }
            msg.Result = dt;
        }

        #endregion

        #region 成果列表
        /// <summary>
        /// 成果列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETCGLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWhere = " Status='1' and Type=" + P1;

            if (P2 != "")
            {
                strWhere += " and Title like '%" + P2 + "%'";
            }

            string year = context.Request.QueryString["year"] ?? "";
            if (year != "")
            {
                strWhere += " and year(CRDate) = '" + year + "'";
            }

            int page = 0;
            int pagecount = 8;
            int.TryParse(context.Request.QueryString["p"] ?? "1", out page);
            int.TryParse(context.Request.QueryString["pagecount"] ?? "8", out pagecount);//页数
            page = page == 0 ? 1 : page;
            int total = 0;
            DataTable dt = new DataTable();
            dt = new JH_MH_XWGLB().GetDataPager("JH_CG_CGGL ", "*", pagecount, page, " CRDate desc", strWhere, ref total);

            msg.Result = dt;
            msg.Result1 = total;
        }
        /// <summary>
        /// 获取班组创新成果和优秀QC成果（大屏展示用）
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETBZQCLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {

            DataTable dtBZDATA = new DataTable();
            dtBZDATA = new JH_MH_XWGLB().GetDTByCommand("SELECT DISTINCT  SUBSTRING( CONVERT(varchar(100), CRDate, 112) ,0,5)  AS CGYEAY FROM JH_CG_CGGL  ORDER BY SUBSTRING( CONVERT(varchar(100), CRDate, 112) ,0,5) DESC");
            dtBZDATA.Columns.Add("BZCGList", Type.GetType("System.Object"));
            foreach (DataRow dr in dtBZDATA.Rows)
            {
                DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("SELECT * FROM JH_CG_CGGL INNER JOIN JH_CG_LXGL ON JH_CG_CGGL.Type=JH_CG_LXGL.ID WHERE  TopID='1'  AND Status='1' AND  SUBSTRING( CONVERT(varchar(100), JH_CG_CGGL.CRDate, 112) ,0,5) ='" + dr["CGYEAY"] + "' ");
                dr["BZCGList"] = dtItem;
            }
            msg.Result = dtBZDATA;

            DataTable dtQCDATA = new DataTable();
            dtQCDATA = new JH_MH_XWGLB().GetDTByCommand("SELECT DISTINCT  SUBSTRING( CONVERT(varchar(100), CRDate, 112) ,0,5)  AS CGYEAY FROM JH_CG_CGGL");
            dtQCDATA.Columns.Add("QCCGList", Type.GetType("System.Object"));
            foreach (DataRow dr in dtQCDATA.Rows)
            {
                DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("SELECT * FROM JH_CG_CGGL INNER JOIN JH_CG_LXGL ON JH_CG_CGGL.Type=JH_CG_LXGL.ID WHERE  TopID='5'  AND Status='1' AND  SUBSTRING( CONVERT(varchar(100), JH_CG_CGGL.CRDate, 112) ,0,5) ='" + dr["CGYEAY"] + "' ");
                dr["QCCGList"] = dtItem;
            }
            msg.Result1 = dtQCDATA;

        }




        #endregion

        #region 成果内容
        /// <summary>
        /// 成果内容
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETCG(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var nr = new JH_CG_CGGLB().GetEntities(" ID='" + P1 + "' ").FirstOrDefault();

            msg.Result = nr;
            if (!string.IsNullOrEmpty(nr.Files1))
            {
                msg.Result1 = new JH_Auth_FormAttchgB().GetDTByCommand("SELECT ID,FileOldName,FileUrl FROM  JH_Auth_FormAttchg WHERE  ID IN (" + nr.Files1 + ")");
            }
            if (!string.IsNullOrEmpty(nr.Files2))
            {
                msg.Result2 = new JH_Auth_FormAttchgB().GetDTByCommand("SELECT ID,FileOldName,FileUrl FROM  JH_Auth_FormAttchg WHERE ID  IN (" + nr.Files2 + ")");
            }
            if (!string.IsNullOrEmpty(nr.Files3))
            {
                msg.Result3 = new JH_Auth_FormAttchgB().GetDTByCommand("SELECT ID,FileOldName,FileUrl FROM  JH_Auth_FormAttchg WHERE ID IN (" + nr.Files3 + ")");
            }
        }

        #endregion

        #endregion

        #region 专利展示
        public void GETZLFL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select Name as name,'n' as issel from JH_CG_ZLFL WHERE  IsDel=0  order by CRDate desc ");


            msg.Result = dt;
        }

        public void GETZLFLLISTNEW(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            //分页，暂不用
            int page = 0;
            int pagecount = 1000;
            int.TryParse(context.Request.QueryString["p"] ?? "1", out page);
            int.TryParse(context.Request.QueryString["pagecount"] ?? "8", out pagecount);//页数
            page = page == 0 ? 1 : page;
            int total = 0;
            int sta = 1;
            //分页，暂不用


            string strWhere = "1=1";
            string strHY = P1.TrimEnd(',');
            string strLX = P2.TrimEnd(',');
            string strMC = context.Request["MC"] ?? "";
            string strZY = context.Request["ZY"] ?? ""; ;
            string strGJZ = context.Request["GJZ"] ?? "";
          //  and year(CRDate) = '" + year + "'";

             strWhere = strWhere + " and status = '" + sta + "'";

            if (strHY != "")
            {
                strWhere = strWhere + " AND hangye in ('" + strHY.ToFormatLike(',') + "')";
            }
            if (strLX != "")
            {
                strWhere = strWhere + " AND Remark in ('" + strLX.ToFormatLike(',') + "')";

            } if (strMC != "")
            {
                strWhere = strWhere + " AND Name like '%" + strMC + "%' ";
            } if (strZY != "")
            {
                strWhere = strWhere + " AND Details like '%" + strZY + "%' ";
            } if (strGJZ != "")
            {
                strWhere = strWhere + " AND guanjianci like '%" + strGJZ + "%' ";
            }

            

            DataTable dt = new DataTable();
            dt = new JH_MH_XWGLB().GetDataPager("JH_CG_FMZL ", "*", pagecount, page, " CRDate desc", strWhere, ref total);

           

            msg.Result = dt;
            msg.Result1 = total;
        }
        #region 类型列表
        /// <summary>
        /// 类型列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETZLFLLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            DataTable dt = new JH_MH_LMGLB().GetDTByCommand(" select * from JH_CG_ZLFL where TopID=0 and IsDel=0  order by CRDate desc ");

            dt.Columns.Add("Item", Type.GetType("System.Object"));
            foreach (DataRow dr in dt.Rows)
            {
                DataTable dtItem = new JH_MH_LMGLB().GetDTByCommand("select * from JH_CG_ZLFL where  TopID=" + dr["ID"].ToString() + " and IsDel=0  order by CRDate desc ");
                dr["Item"] = dtItem;
            }
            msg.Result = dt;
        }

        #endregion

        #region 专利内容列表
        /// <summary>
        /// 专利内容列表
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETZLLIST(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWhere = " Type=" + P1;

            if (P2 != "")
            {
                strWhere += " and Title like '%" + P2 + "%'";
            }

            string year = context.Request.QueryString["year"] ?? "";
            if (year != "")
            {
                strWhere += " and year(CRDate) = '" + year + "'";
            }

            int page = 0;
            int pagecount = 8;
            int.TryParse(context.Request.QueryString["p"] ?? "1", out page);
            int.TryParse(context.Request.QueryString["pagecount"] ?? "8", out pagecount);//页数
            page = page == 0 ? 1 : page;
            int total = 0;
            DataTable dt = new DataTable();
            dt = new JH_MH_XWGLB().GetDataPager("JH_CG_FMZL ", "*", pagecount, page, "CRDate desc", strWhere, ref total);

            msg.Result = dt;
            msg.Result1 = total;
        }

        #endregion

        #region 专利内容
        /// <summary>
        /// 专利内容
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETZL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            var nr = new JH_CG_FMZLB().GetEntities(" ID='" + P1 + "' ").FirstOrDefault();
            msg.Result = nr;
        }

        #endregion

        #endregion

        #region 转换图片



        #region 图片转换器工厂
        /// <summary>
        /// 图片转换器工厂。
        /// </summary>

        #endregion



        #endregion
    }
}